import requests
import base64


API_URL = "https://api-inference.huggingface.co/models/cloudqi/cqi_text_to_image_pt_v0"
headers = {"Authorization": f"Bearer {'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'}"}


def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.content


image_bytes = query({
    "inputs": "The scenery of the city is like a splendid picture, and the busy streets and alleys flow with brilliant brilliance. High-rise buildings are stacked on top of each other, and the dazzling neon lights paint a dreamy picture at night. With a lot of traffic, people coming and going, the pulse of the city beats with endless vitality. Parks and squares are oases of rest, where flowers and trees give tranquility amid the hustle and bustle of the city. The city's gastronomic culture is rich and varied, and a variety of delicious foods are tempting to satisfy the cravings of the taste buds. In this city, people chase dreams, create miracles, and life is like a beautiful music, full of hope and possibility. No matter how sad it is, the cityscape will always heal your heart at some point and make you smile again."
})
# You can access the image with PIL.Image for example
image_stream = base64.b64encode(image_bytes)
image_bs64 = image_stream.decode('utf-8')
print("data:image/png;base64,"+image_bs64)
